import 'package:f_demo_one/views/detail_page.dart';
import 'package:flutter/material.dart';

class HomePage extends StatelessWidget {
  const HomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        title: const Text('首页'),
      ),
      body: Container(
        width: double.infinity,
        height: double.infinity,
        decoration: const BoxDecoration(color: Colors.black12),
        child: Column(
          children: [
            const Text('首页'),
            ElevatedButton(
              onPressed: () {
                // 方式一 页面跳转
                // 点击按钮后，跳转到详情页，并传递参数
                Navigator.push(
                  context,
                  MaterialPageRoute(
                    builder: (context) => const DetailPage(),
                  ),
                );
              },
              child: const Text('去详情页--方式一'),
            ),
            ElevatedButton(
                onPressed: () {
                  // 方式二 页面跳转
                  // 点击按钮后，跳转到详情页，并传递参数
                  Navigator.pushNamed(
                    context,
                    '/detail',
                    arguments: {'name': '张三', 'age': 18},
                  );
                },
                child: const Text('去详情页--方式二'))
          ],
        ),
      ),
    );
  }
}
